package org.example.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * @author 张在成
 */
@Configuration
public class RestConfig {

//    @Autowired
//    private LoadBalancerClient loadBalancerClient;
//
//    @Bean
//    @LoadBalanced
//    public RestTemplate restTemplate(){
//        RestTemplate restTemplate=new RestTemplate();
//        restTemplate.setInterceptors(Collections.singletonList(new LoadBalancerInterceptor(loadBalancerClient)));
//        return restTemplate;
//    }

    /**
     * 如果采用了LoadBanlancerClient就将该@LoadBalanced注释掉
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        RestTemplate restTemplate=new RestTemplate();
        return restTemplate;
    }

    /**
     * 全局的随机轮询策略
     */
//    @Bean
//    public RandomRule randomRule(){
//        return  new RandomRule();
//    }


}
